'use strict';







module.exports = class IndexController extends require('egg').Controller {
    async index() {
        const { ctx } = this;
        var { id } = ctx.query;
        ctx.model.Comment.hasMany(ctx.model.ReplyComment, { sourceKey: 'commentId', foreignKey: 'replyCommentId' })
        let where = {
            answerId: id,
        }
        var data = await ctx.model.Comment.findAll({
            where,
            include: ctx.model.ReplyComment
        });
        ctx.body = {
            code: 200,
            data: data,
        }
    }
    async show() {
        const { ctx } = this;
        var data = ctx.request.body;
        if (data.replyId) {
            console.log(data);
            ctx.model.ReplyComment.create(data);
            ctx.body = {
                data: data,
                code: 200
            };

        } else {
            await ctx.model.Comment.create(data);
            ctx.body = {
                data: data,
                code: 200
            };
        }
    }




}
